// let [a,b,c] = [1,2,3];
// console.log(a,b,c);

document.getElementById("div").innerHTML = "insert successfully!";

let a;
({a} = {a:'link'});
console.log(a);

let [e,f,g] = 'hello';
console.log(e,f,g);

let str = 'this is my es6 study';
let strResult = `How to study es6? ${str}`;
console.log(strResult.includes('es6'));

console.log(Number.MAX_SAFE_INTEGER);
console.log(Number.MIN_SAFE_INTEGER);

let num = 198.1;
console.log(Number.parseFloat(num));

let json = {
    '0': 'a',
    '1': 'b',
    '2': 'c',
    length: 3
};
console.log(json[1]);
console.log(Array.from(json));


console.log(Array.of(1,2,3,4));

let result = ['a','b','c','d','e'];
console.log(
    result.find(function(value,index,attr){
        return value > 'e'
    })
);


let fillStr = ['this','si','es6'];
fillStr.fill('is',1,2);
console.log(fillStr);

let forAttr = ['this','is','es6'];
for(let item of forAttr){
    console.log(item);
}

for(let item of forAttr.keys()){
    console.log(item);
}

for(let [key,val] of forAttr.entries()){
    console.log(`下标是${key},实际值是${val}`);
}

var add = (a,b) => a+b;
console.log(add(1,2));

let obj={
    'a':1,
    'b':2
 }
 console.log('a' in obj);   true


let obj2 = {
    a:'this',
    b:'is',
    c:'es6'
};
let getObj2 = ({a,b,c}) => console.log(a,b,c);
getObj2(obj2);

let num2 = [1,2,3,4];
let add2 = (a,b,c,d) => console.log(a+b+c+d);
add2(...num2);

let name = 'Jack';
let skill = 'swiming';
var obj3 = {name,skill};
console.log(obj3);

let key = 'name';
var obj4 = {
    [key]: 'Jhon'
}
console.log(obj4.name);

var objA = {name:'Lily'};
var objB = {age:20};
let newObj = Object.assign(objA,objB);
console.log(newObj);


let pObj = {
    name: 'lucy',
    age: 20
};
let job = Symbol();
pObj[job] = 'teacher';
for(let i in pObj){
    console.log(pObj[i]);
}


// let setArr = new Set([1,2,3,4,5]);
// setArr.add(6)
// console.log(setArr);
// console.log(setArr.has(3));
// setArr.delete(3)
// setArr.clear();
// console.log(setArr.size);

// let weakObj=new WeakSet();
// let oj={a:'jspang',b:'技术胖'}
// weakObj.add(oj);
 
// console.log(weakObj);


let map = new Map();
let data = {
    'title':'this is es6 title',
    'link':'www.baidu.com'
}
map.set(a,data);
console.log(map.size);

var target = {
    add:function(val){
        return val+100;
    },
    name:'Mike'
}

var handler = {
    get:function(target,value,property){
        console.log('get钩子执行成功');
        return target;
    },
    set:function(target,key,value,receiver){
        console.log('set钩子执行成功');
        console.log(`设置${key}=${value}`);
        return target;
    }

}

var pro = new Proxy(target,handler)
pro.name='Mike Jhon';
console.log(pro.name);


var target2 = function(a,b){
    return a+b
}

var handler2 =  {
    apply(target,ctx,args){
        console.log(ctx);
        return Reflect.apply(...arguments)
    }
}

var pro2 = new Proxy(target2,handler2);
console.log(pro2(1,2));


var area = 1;
function step1(resolve,reject){
    if(++area <= 3){
        resolve('第一步计算小于3')
    }else{
        reject('第一步计算值超出范围')
    }
}
function step2(resolve,reject){
    if(++area <= 3){
        resolve('第二步计算小于3')
    }else{
        reject('第二步计算值超出范围')
    }
}
function step3(resolve,reject){
    if(++area <= 3){
        resolve('第三步计算小于3')
    }else{
        reject('第三步计算值超出范围')
    }
}

new Promise(step1).then(function(val){
    console.log(val);
    return new Promise(step2);
}).then(function(val){
    console.log(val);
    return new Promise(step3);
}).then(function(val){
    console.log(val);
});


